
AM_MAKEFLAGS = --no-print-directory

includedir = @includedir@/connman

include_HEADERS = include/types.h include/log.h include/plugin.h \
			include/security.h include/notifier.h \
			include/storage.h include/service.h \
			include/device.h include/network.h include/inet.h \
			include/crypto.h include/blob.h include/dns_client.h

nodist_include_HEADERS = include/version.h

noinst_HEADERS = include/driver.h include/element.h include/property.h \
			include/rtnl.h include/wifi.h include/task.h \
			include/dbus.h include/rfkill.h include/option.h \
			include/resolver.h include/ipconfig.h \
			include/profile.h include/provider.h \
			include/assert.h


local_headers = $(foreach file,$(include_HEADERS) $(nodist_include_HEADERS) \
			$(noinst_HEADERS), include/connman/$(notdir $(file)))


gdbus_sources = gdbus/gdbus.h gdbus/mainloop.c gdbus/object.c gdbus/watch.c

if DATAFILES
dbusdir = @DBUS_DATADIR@

dbus_DATA = src/flimflam.conf
endif

plugin_LTLIBRARIES =

plugin_objects =

builtin_modules =
builtin_sources =
builtin_libadd =
builtin_cflags =

noinst_PROGRAMS =

sbin_PROGRAMS = src/flimflamd

src_flimflamd_SOURCES = $(gdbus_sources) $(builtin_sources) \
			src/main.c src/connman.h src/log.c \
			src/error.c src/plugin.c src/task.c src/element.c \
			src/device.c src/network.c src/connection.c \
			src/manager.c src/portal.c src/profile.c src/service.c \
			src/agent.c src/notifier.c src/provider.c \
			src/security.c src/resolver.c src/ipconfig.c \
			src/storage.c src/rfkill.c src/rtnl.c \
			src/inet.c src/wifi.c src/dbus.c src/crypto.c \
			src/ipv4.c src/ipv6.c src/blob.c src/dns_client.c


if UDEV
src_flimflamd_SOURCES += src/udev.c
else
src_flimflamd_SOURCES += src/udev-compat.c
endif

src_flimflamd_LDADD = $(builtin_libadd) @GLIB_LIBS@ @GTHREAD_LIBS@ \
			@DBUS_LIBS@ @UDEV_LIBS@ @CARES_LIBS@ -lcurl -ldl

src_flimflamd_LDFLAGS = -Wl,--export-dynamic -Wl,--version-script=src/flimflam.ver

src_flimflamd_DEPENDENCIES = src/flimflam.ver

CLEANFILES = src/flimflam.ver src/flimflam.exp src/flimflam.conf \
						scripts/wpa_supplicant.conf \
						src/builtin.h $(local_headers)

statedir = $(localstatedir)/run/flimflam

plugindir = $(libdir)/flimflam/plugins

scriptdir = $(libdir)/flimflam/scripts

storagedir = $(localstatedir)/cache/flimflam

storage_homedir = @STORAGE_HOMEDIR@

testdir  = $(libdir)/flimflam/test

if MAINTAINER_MODE
build_plugindir = $(abs_top_srcdir)/plugins/.libs
build_scriptdir = $(abs_top_srcdir)/scripts
else
build_plugindir = $(plugindir)
build_scriptdir = $(scriptdir)
endif

AM_CFLAGS = -Wall -Werror \
		@UDEV_CFLAGS@ @NETLINK_CFLAGS@ @DBUS_CFLAGS@ \
		@GLIB_CFLAGS@ @GTHREAD_CFLAGS@ @SSL_ROOTS_CFLAGS@ \
		@ENABLE_NSS_CFLAGS@ @CARES_CFLAGS@ \
		$(builtin_cflags) \
				-DCONNMAN_PLUGIN_BUILTIN \
				-DSTATEDIR=\""$(statedir)"\" \
				-DPLUGINDIR=\""$(build_plugindir)"\" \
				-DSCRIPTDIR=\""$(build_scriptdir)"\" \
				-DSTORAGEDIR=\""$(storagedir)\"" \
				-DSTORAGE_HOMEDIR=\""${storage_homedir}"\"

INCLUDES = -I$(builddir)/include -I$(builddir)/src -I$(srcdir)/gdbus

EXTRA_DIST = src/genbuiltin src/flimflam-dbus.conf src/flimflam-polkit.conf \
		scripts/wpa_supplicant.conf


script_DATA =
script_PROGRAMS =
script_SCRIPTS =
script_LTLIBRARIES =

include Makefile.plugins

if CLIENT
noinst_PROGRAMS += client/cm

client_cm_SOURCES = client/main.c
client_cm_LDADD = @DBUS_LIBS@
endif

if TOOLS
noinst_PROGRAMS += tools/wifi-scan tools/addr-test tools/tap-test

tools_wifi_scan_LDADD = @GLIB_LIBS@ @NETLINK_LIBS@
endif

if TESTTOOLS
test_SCRIPTS = \
	test/activate-service \
	test/add-ipconfig \
	test/clr-ipconfig \
	test/clr-service-property \
	test/connect-service \
	test/connect-wifi \
	test/debug \
	test/debug-flimflam \
	test/disable-device \
	test/disconnect-service \
	test/delete-entry \
	test/dump-profile \
	test/enable-device \
	test/get-portal-list \
	test/get-portal-url \
	test/get-state \
	test/list-devices \
	test/list-entries \
	test/list-ipconfigs \
	test/list-networks \
	test/list-profiles \
	test/list-services \
	test/mm-activate \
	test/mm-connect \
	test/mm-disable \
	test/mm-disconnect \
	test/mm-enable \
	test/mm-factory-reset \
	test/mm-list-modems \
	test/mm-reset \
	test/mm-set-carrier \
	test/mm-status \
	test/mm.py \
	test/monitor-flimflam \
	test/monitor-services \
	test/rm-ipconfig \
	test/service-order \
	test/set-address \
	test/set-apn \
	test/set-bgscan \
	test/set-device-property \
	test/set-ipconfig \
	test/set-mtu \
	test/set-passphrase \
	test/set-portal-list \
	test/set-portal-url \
	test/set-service-property \
	test/show-introspection \
	test/simple-agent \
	test/start-scanning \
	test/test-agent \
	test/test-compat \
	test/test-flimflam \
	test/test-manager \
	test/test-profile
endif

EXTRA_DIST += doc/overview-api.txt doc/behavior-api.txt \
				doc/ipconfig-api.txt doc/plugin-api.txt \
				doc/manager-api.txt doc/agent-api.txt \
				doc/profile-api.txt doc/service-api.txt \
				doc/device-lowlevel-api.txt \
				doc/network-lowlevel-api.txt

pkgconfigdir = $(libdir)/pkgconfig

pkgconfig_DATA = flimflam.pc

DISTCHECK_CONFIGURE_FLAGS = --disable-gtk-doc \
				--disable-datafiles \
				--enable-loopback \
				--enable-ethernet \
				--enable-wifi \
				--enable-bluetooth \
				--enable-ofono \
				--enable-udhcp \
				--enable-dhclient \
				--enable-resolvconf \
				--enable-dnsproxy \
				--enable-udev \
				--enable-polkit \
				--enable-client \
				--enable-tools \
				--enable-hostroute

DISTCLEANFILES = $(pkgconfig_DATA)

MAINTAINERCLEANFILES = Makefile.in \
	aclocal.m4 configure config.h.in config.sub config.guess \
	ltmain.sh depcomp compile missing install-sh mkinstalldirs


src/plugin.$(OBJEXT): src/builtin.h

src/builtin.h: src/genbuiltin $(builtin_sources)
	$(AM_V_GEN)$(srcdir)/src/genbuiltin $(builtin_modules) > $@

src/flimflam.exp: $(src_flimflamd_OBJECTS)
	$(AM_V_GEN)$(NM) $^ | $(AWK) '{ print $$3 }' | sort -u | \
				$(EGREP) -e '^connman_' -e '^g_dbus_' > $@

src/flimflam.ver: src/flimflam.exp
	$(AM_V_at)echo "{ global:" > $@
	$(AM_V_GEN)$(SED) -e "s/\(.*\)/\1;/" $< >> $@
	$(AM_V_at)echo "local: *; };" >> $@

src/flimflam.conf: src/flimflam-dbus.conf src/flimflam-polkit.conf
if POLKIT
	$(AM_V_GEN)cp $(srcdir)/src/flimflam-polkit.conf $@
else
	$(AM_V_GEN)cp $(srcdir)/src/flimflam-dbus.conf $@
endif

scripts/wpa_supplicant.conf: scripts/wpa_supplicant.conf.in
	sed -e 's|@libdir[@]|${libdir}|' < $< > $@

$(src_flimflamd_OBJECTS) $(plugin_objects): $(local_headers)

include/connman/version.h: include/version.h
	$(AM_V_at)$(MKDIR_P) include/connman
	$(AM_V_GEN)$(LN_S) $(abs_top_builddir)/$< $@

include/connman/%.h: include/%.h
	$(AM_V_at)$(MKDIR_P) include/connman
	$(AM_V_GEN)$(LN_S) $(abs_top_srcdir)/$< $@

clean-local: include/connman
	@$(RM) -r $<
